//
//  UIButton+Ext.swift
//  Swift
//
//  Created by 贺瑞 on 2017/8/2.
//  Copyright © 2017年 herui. All rights reserved.
//

import UIKit


extension UIButton {
    
    private func toHighlight(_ normal:String) -> String {
        return normal + "_highlighted"
    }
    private func getNormalImage(_ imageName:String) -> UIImage? {
        return UIImage(named: imageName)
    }
    private func getHighlightImage(_ imageName:String) -> UIImage? {
        return UIImage(named: toHighlight(imageName))
    }
    
    convenience init(imageName:String, bgImageName:String){
        
        self.init(imageName: imageName)
        setBackgroundImage(getNormalImage(bgImageName), for: .normal)
        setBackgroundImage(getHighlightImage(bgImageName), for: .highlighted)
        sizeToFit()
    }
    
    convenience init(imageName:String){
        self.init()
        
        setImage(getNormalImage(imageName), for: .normal)
        setImage(getHighlightImage(imageName), for: .highlighted)
        sizeToFit()
    }

}

